<template>

  <iframe :id='id' :src='url' frameborder='0' style="display:block"  width='100%'  height='1000'   scrolling="no" ></iframe>

</template>

<script>
import Vue from 'vue'
import { ACCESS_TOKEN } from '@/store/mutation-types'
import PageLayout from '../page/PageLayout'
import RouteView from './RouteView'
import { getAction } from '@api/manage'

export default {
  name: 'IframePageContent',
  inject: ['closeCurrent'],
  data() {
    return {
      url: '',
      id: ''
    }
  },
  created() {
   // this.setIframeHeight(document.getElementById('external-frame'));
    this.goUrl()
  },
  updated() {
    this.goUrl()
  },
  watch: {
    $route(to, from) {
      this.goUrl()
    }
  },
  methods: {
//   setIframeHeight(iframe) {
//   if (iframe) {
//     var iframeWin = iframe.contentWindow || iframe.contentDocument.parentWindow;
//     if (iframeWin.document.body) {
//       iframe.height = iframeWin.document.documentElement.scrollHeight || iframeWin.document.body.scrollHeight;
//     }
//   }
// },


goUrl()
{
  getAction("/sys/permission/getIndexUrl").then(res => {
    if (res.success && res.result) {

      let url=res.result;
      if (url !== null && url !== undefined) {
        //-----------------------------------------------------------------------------------------
        //url支持通过 ${token}方式传递当前登录TOKEN
        let tokenStr = '${token}'
        if (url.indexOf(tokenStr) != -1) {
          let token = Vue.ls.get(ACCESS_TOKEN)
          this.url = url.replace(tokenStr, token)
        } else {
          this.url = url
        }
        //-----------------------------------------------------------------------------------------

        /*update_begin author:wuxianquan date:20190908 for:判断打开方式，新窗口打开时this.$route.meta.internalOrExternal==true */
        if (this.$route.meta.internalOrExternal != undefined && this.$route.meta.internalOrExternal == true) {
          this.closeCurrent()
          window.open(this.url)
        }
        /*update_end author:wuxianquan date:20190908 for:判断打开方式，新窗口打开时this.$route.meta.internalOrExternal==true */

      }

    }})


}
}
}
</script>

<style>
</style>